﻿
using System.Collections.Generic;
using UnityEngine;

public class MonoGameObject2Lua : MonoObj2Lua
{
	public static Dictionary<GameObject, XLua.LuaTable> obj2lua = new Dictionary<GameObject, XLua.LuaTable>();
	public static void AddObjWithLua(GameObject obj, XLua.LuaTable lua)
    {
		obj2lua[obj] = lua;
	}

	protected override XLua.LuaTable OnGetLuaIns()
	{
		XLua.LuaTable ins;
		if (obj2lua.TryGetValue(this.gameObject, out ins))
        {
			//debug only
			var tostring = LuaMgr.luaEnv.Global.Get<XLua.LuaFunction>("tostring");
			_luaName = tostring.Func<XLua.LuaTable, string>(ins);

			return ins;
        }
		Debug.LogError("Can not find ins:" + this.gameObject.name);
		return null;
	}

	protected override void OnDestroy()
	{
		obj2lua.Remove(this.gameObject);
		base.OnDestroy();
	}
}